/** 文件作用：科目按钮精灵
 *	创建时间：2012-11-17 下午7:49:28
 *  作者： 陈相伯 
 *  描述：
 */
package com.kingPadStudy.sprite.children;

import android.R.integer;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Message;
import android.view.View;

import com.kingPadStudy.activity.KingPadStudyActivity;
import com.kingPadStudy.constant.Constant;
import com.kingPadStudy.controller.ViewController;
import com.kingPadStudy.resource.ResourceLoader;
import com.kingPadStudy.sprite.AnimationImageSprite;

/**
 * 描述：科目按钮精灵
 *
 */
public class MajorButtonSprite extends AnimationImageSprite{
	
	public MajorButtonSprite(Bitmap bmp, float x, float y) {
		super(bmp, x, y);
	}
	
	
	/**
	 * 构造函数：
	 * @param bmp
	 * @param x
	 * @param y
	 * @param type
	 */
	public MajorButtonSprite(Bitmap bmp, float x, float y,int type,View father) {
		super(bmp, x, y,father); 
		type_Major = type;
	}
	
	
	 
	
	@Override
	public void onTouch(float tx, float ty) {
		if(tx>= this.x && tx<= this.x+this.width && ty>=this.y && ty<=this.y + this.height){
			KingPadStudyActivity.showWaitDialog();
			jump();
		}
	}
	

	/**
	 * 函数作用：跳转
	 * void
	 */
	protected void jump(){
		switch(type_Major){
		case Constant.MAJOR_CHINESE:
			ResourceLoader.loadBigBookData("/mnt/sdcard/kingpad/data/Chinese/人教版_2a","/mnt/sdcard/kingpad/data/Chinese",Constant.MAJOR_CHINESE);
			break;
		case Constant.MAJOR_MATH:
			ResourceLoader.loadBigBookData("/mnt/sdcard/kingpad/data/Math/北师版_2a","/mnt/sdcard/kingpad/data/Math",Constant.MAJOR_MATH);
			break;
		case Constant.MAJOR_ENGLISH:
			ResourceLoader.loadBigBookData("/mnt/sdcard/kingpad/data/English/人教新版（一年级起）_2a","/mnt/sdcard/kingpad/data/English",Constant.MAJOR_ENGLISH);
			break;
		}
		Message message = new Message();
		message.what =  Constant.VIWE_MAJOR;
		System.out.println("跳转"+type_Major);
		message.arg1 = type_Major;
		KingPadStudyActivity.handler.sendMessage(message);
	}
 
	
	

	@Override
	public void onDraw(Canvas canvas) {
		 int w_move = 0;
		 int h_move = 0;
		 if(this.scale != 1){
			 w_move = (int)(this.width*(scale-1));
			 h_move = (int)(this.height*(scale-1));
		 }
		 Rect rect_dist = new Rect((int)x-w_move, (int)y-h_move, (int)(x+width*scale), (int)(y+height*scale) ); 
		 Rect rect_src = new Rect(0,0, (int)(width*scale) ,(int)(height*scale));
		 canvas.drawBitmap(this.bitmap, rect_src, rect_dist,null);
	}

	private int type_Major = -1;
}
